home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / mysql / scripts / mysql_upgrade < prev    next >
Encoding:
Text File  |  2006-04-26  |  5.1 KB  |  204 lines

  1. #!/bin/sh
  2. # Copyright (C) 2002-2003 MySQL AB
  3. # For a more info consult the file COPYRIGHT distributed with this file.
  4.  
  5. # Runs mysqlcheck --check-upgrade in case it has not been done on this
  6. # major MySQL version
  7.  
  8. # This script should always be run when upgrading from one major version
  9. # to another (ie: 4.1 -> 5.0 -> 5.1)
  10.  
  11. #
  12. # Note that in most cases one have to use '--password' as
  13. # arguments as these needs to be passed on to the mysqlcheck command
  14.  
  15.  
  16. user=root
  17.  
  18. case "$1" in
  19.     --no-defaults|--defaults-file=*|--defaults-extra-file=*)
  20.       defaults="$1"; shift
  21.       ;;
  22. esac
  23.  
  24. parse_arguments() {
  25.   # We only need to pass arguments through to the server if we don't
  26.   # handle them here.  So, we collect unrecognized options (passed on
  27.   # the command line) into the args variable.
  28.   pick_args=
  29.   if test "$1" = PICK-ARGS-FROM-ARGV
  30.   then
  31.     pick_args=1
  32.     shift
  33.   fi
  34.  
  35.   for arg do
  36.     case "$arg" in
  37.       --basedir=*) MY_BASEDIR_VERSION=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  38.       --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  39.       --ldata=*|--data=*|--datadir=*) DATADIR=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  40.       --force) force=1 ;;
  41.       --verbose) verbose=1 ;;
  42.       --help) help_option=1 ;;
  43.       *)
  44.         if test -n "$pick_args"
  45.         then
  46.           # This sed command makes sure that any special chars are quoted,
  47.           # so the arg gets passed exactly to the server.
  48.           args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.=-]\),\\\\\1,g'`
  49.         fi
  50.         ;;
  51.     esac
  52.   done
  53. }
  54.  
  55. #
  56. # Find where my_print_defaults is
  57. #
  58.  
  59. find_my_print_defaults () {
  60.   if test -x ./bin/my_print_defaults
  61.   then
  62.     print_defaults="./bin/my_print_defaults"
  63.   elif test -x ./extra/my_print_defaults
  64.   then
  65.     print_defaults="./extra/my_print_defaults"
  66.   elif test -x /usr/local/bin/my_print_defaults
  67.   then
  68.     print_defaults="/usr/local/bin/my_print_defaults"
  69.   elif test -x /usr/local/bin/mysql_print_defaults
  70.   then
  71.     print_defaults="/usr/local/bin/mysql_print_defaults"
  72.   else
  73.     print_defaults="my_print_defaults"
  74.   fi
  75. }
  76.  
  77. find_my_print_defaults
  78.  
  79. # Get first arguments from the my.cfg file, groups [mysqld] and
  80. # [mysql_upgrade], and then merge with the command line arguments
  81.  
  82. args=
  83. DATADIR=
  84. bindir=
  85. MY_BASEDIR_VERSION=
  86. verbose=0
  87. force=0
  88. help_option=0
  89.  
  90. parse_arguments `$print_defaults $defaults mysqld mysql_upgrade`
  91. parse_arguments PICK-ARGS-FROM-ARGV "$@"
  92.  
  93. if test $help_option = 1
  94. then
  95.   echo "MySQL utility script to upgrade database to the current server version"
  96.   echo ""
  97.   echo "It takes the following arguments:"
  98.   echo "  --help     Show this help message"
  99.   echo "  --basedir  Specifies the directory where MySQL is installed"
  100.   echo "  --datadir  Specifies the data directory"
  101.   echo "  --force    Mysql_upgrade.info file will be ignored"
  102.   echo "  --user     Username for server login if not current user"
  103.   echo "  --verbose  Display more output about the process"
  104.   echo ""
  105.  
  106.   exit 0
  107. fi
  108.  
  109. #
  110. # Try to find where binaries are installed
  111. #
  112.  
  113. MY_PWD=`pwd`
  114. # Check for the directories we would expect from a binary release install
  115. if test -z "$MY_BASEDIR_VERSION"
  116. then
  117.   if test -f ./share/mysql/english/errmsg.sys -a -x ./bin/mysqld
  118.   then
  119.     MY_BASEDIR_VERSION=$MY_PWD            # Where bin, share and data are
  120.     bindir="$MY_BASEDIR_VERSION/bin"
  121.   # Check for the directories we would expect from a source install
  122.   elif test -f ./share/mysql/english/errmsg.sys -a -x ./libexec/mysqld
  123.   then
  124.     MY_BASEDIR_VERSION=$MY_PWD            # Where libexec, share and var are
  125.     bindir="$MY_BASEDIR_VERSION/bin"
  126. # Since we didn't find anything, used the compiled-in defaults
  127.   else
  128.     MY_BASEDIR_VERSION=/usr/local
  129.     bindir=/usr/local/bin
  130.   fi
  131. else
  132.   bindir="$MY_BASEDIR_VERSION/bin"
  133. fi
  134.  
  135. #
  136. # Try to find the data directory
  137. #
  138.  
  139. if test -z "$DATADIR"
  140. then
  141.   # Try where the binary installs put it
  142.   if test -d $MY_BASEDIR_VERSION/data/mysql
  143.   then
  144.     DATADIR=$MY_BASEDIR_VERSION/data
  145.   # Next try where the source installs put it
  146.   elif test -d $MY_BASEDIR_VERSION/var/mysql
  147.   then
  148.     DATADIR=$MY_BASEDIR_VERSION/var
  149.   # Or just give up and use our compiled-in default
  150.   else
  151.     DATADIR=/usr/local/var
  152.   fi
  153. fi
  154.  
  155. if test ! -x "$bindir/mysqlcheck"
  156. then
  157.   echo "Can't find program '$bindir/mysqlcheck'"
  158.   echo "Please restart with --basedir=mysql-install-directory"
  159.   exit 1
  160. fi
  161.  
  162. if test ! -f "$DATADIR/mysql/user.frm"
  163. then
  164.   echo "Can't find data directory. Please restart with --datadir=path-to-data-dir"
  165.   exit 1
  166. fi
  167.  
  168. CHECK_FILE=$DATADIR/mysql_upgrade.info
  169.  
  170. if test -f $CHECK_FILE -a $force = 0
  171. then
  172.   version=`cat $CHECK_FILE`
  173.   if test "$version" = "5.0"
  174.   then
  175.     if test $verbose = 1
  176.     then
  177.        echo "mysql_upgrade already done for this version"
  178.     fi
  179.     $bindir/mysql_fix_privilege_tables --silent $args
  180.     exit 0
  181.   fi
  182. fi
  183.  
  184. #
  185. # Run the upgrade
  186. #
  187.  
  188. check_args="--check-upgrade --all-databases --auto-repair --user=$user"
  189.  
  190. if test $verbose = 1
  191. then
  192.   echo "Running $bindir/mysqlcheck $args $check_args"
  193. fi
  194.  
  195. $bindir/mysqlcheck $check_args $args
  196. if [ $? = 0 ]
  197. then
  198.   # Remember base version so that we don't run this script again on the
  199.   # same base version
  200.   echo "5.0" > $CHECK_FILE
  201. fi
  202.  
  203. $bindir/mysql_fix_privilege_tables --silent --user=$user $args
  204.